package com.yhc.order.server.service.impl;

import com.yhc.order.server.entity.OrderRecordEntity;
import com.yhc.order.server.mapper.OrderRecordMapper;
import com.yhc.order.server.service.IOrderService;
import com.yhc.order.server.service.IUserCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements IOrderService {

    @Autowired
    OrderRecordMapper orderRecordMapper;

    @Autowired
    IUserCacheService userCacheService;


    @Override
    public Long save(Long amount) {

        Long userId = userCacheService.getUserIdWithException();

        OrderRecordEntity orderRecord = OrderRecordEntity.builder()
                .userId(userId)
                .amount(amount)
                .build();
        orderRecordMapper.insert(orderRecord);

        return orderRecord.getId();
    }
}
